package com.example.clock;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.CalendarView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class DateDialog extends Dialog {
    private CalendarView calendarView;

    private OnDateChoseListener listener;

    public void setListener(OnDateChoseListener listener) {
        this.listener = listener;
    }

    public DateDialog(@NonNull Context context) {
        super(context);
    }

    public DateDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected DateDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.chose_date);


        calendarView = (CalendarView) findViewById(R.id.calendarView);
        calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
                if (listener!=null){
                    listener.onDateClicked(year,month+1,dayOfMonth);
                }
            }
        });
    }

    public interface OnDateChoseListener{
        void onDateClicked(int year,int month,int day);
    }
}
